// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import conf from './config/app'
import diytable from './components/tables/diytable'
import ElSearchTablePagination from 'el-search-table-pagination'
import { Message, Loading } from 'element-ui';

import store from './store'

import 'jquery';

Vue.config.productionTip = false
Vue.use(ElementUI);

Vue.use(ElSearchTablePagination)

Vue.component("diytable", diytable); //全局自定义组件

Vue.prototype.fun = conf;
//清空money的值
Vue.prototype.$cls = function (e){
  if(e.target.value == '0.00' || e.target.value == '0') e.target.value = ''
}

//格式化金额
Vue.prototype.$fmoney = function (e){
  console.log("fmoney",e)
  let number = e.target.value
  if(number == '') return '0.00';
  number = number.toString();
  let s = number.replace('/[A-Z]/','').trim()
  let n = 2;
  s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
  console.log('s: ' + s)
  var l = s.split(".")[0].split("").reverse(),
    r = s.split(".")[1];
  let t = "";
  for(let i = 0; i < l.length; i ++ )
  {
    t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
  }
  e.target.value = t.split("").reverse().join("") + "." + r;
}

//showMessage 异步
Vue.prototype.$success =  function (message){
    return new Promise((resolve) => {
    this.$message({
      showClose: true,
      message: message,
      type: 'success',
      onClose: () => {
        resolve() // 当消息关闭时，Promise 完成
      }
    })
  })
}

//全局处理错误
window.onunhandledrejection = event => {
  console.error('未处理的Promise错误:', event.reason);
  // 可选：提示用户或上报错误
   Message.error(event.reason.message)
    event.preventDefault();

};



//20210604 与线上gitt同步
/* eslint-disable no-new */
const app = new Vue({
    el: '#app',
    router,
    components: { App },
    template: '<App/>',
    store
})
